package com.mj.haier.calc.repository;

import com.mj.haier.calc.domain.AzFinSettleCarsteam;
import com.mj.haier.calc.domain.ItfOutcomeStatmentBean;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.List;


/**
 * Spring Data  repository for the AzFinSettleCarsteam entity.
 */
@SuppressWarnings("unused")
@Repository
public interface AzFinSettleCarsteamRepository extends JpaRepository<AzFinSettleCarsteam, Long> {

    @Query(nativeQuery = true,value = "select count(1) as num  from az_fin_settle_carsteam t where t.check_status = '0' AND t.jhi_account = :jhiAccoun")
    int findAllCount(@Param("jhiAccoun") String jhiAccoun );

    @Modifying
    @Transactional
    @Query(nativeQuery = true,value = "update az_fin_settle_carsteam p set p.check_status = '1' where  p.settle_batch_id in (:collection)")
    int batchUpdateBysettleBatchId(@Param("collection") Collection<String> collection);


    @Modifying
    @Transactional
    @Query(nativeQuery = true,value = "update az_fin_settle_carsteam p set p.check_status = '1' where  p.settle_batch_id in (:collection)")
    int batchUpdateBysettleBatchId(@Param("collection") String collection);

    @Modifying
    @Transactional
    @Query(nativeQuery = true,value = "UPDATE az_fin_settle_carsteam t set t.check_status = '3' " +
        "WHERE " +
        "t.fee_type_code = 'carsteam' " +
        "AND t.jhi_Account = ?1 " +
        "AND t.check_status = '0' " +
        "ORDER BY t.id LIMIT ?2")
    int updateLockStatus(String jhiAccount, int size);

    @Modifying
    @Transactional
    @Query(nativeQuery = true,value = "UPDATE az_fin_settle_carsteam t set t.check_status = '0' " +
        "WHERE " +
        "t.fee_type_code = 'carsteam' " +
        "AND t.jhi_Account = ?1 " +
        "AND t.check_status = '3'")
    int updateUpLockStatus(String jhiAccount);

    @Modifying
    @Transactional
    @Query("update AzFinSettleCarsteam a set a.settleEncourageAmounts = :#{#azFinSettleCarsteam.settleEncourageAmounts}, "
        + " a.actualAmounts = :#{#azFinSettleCarsteam.actualAmounts}, a.gmtModified = :#{#azFinSettleCarsteam.gmtModified}, "
        + " a.modifiedUser = :#{#azFinSettleCarsteam.modifiedUser}" 
        + " where a.id = :#{#azFinSettleCarsteam.id}")
	int updateEncourageCash(@Param("azFinSettleCarsteam") AzFinSettleCarsteam azFinSettleCarsteam);




}
